home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / EBKSRC.ARJ / PICKLIST.HPP < prev    next >
C/C++ Source or Header  |  1991-07-30  |  3KB  |  119 lines

  1. /*
  2.     picklist.hpp
  3.     7-30-91
  4.     Demo of coding with FlexList II
  5.  
  6.     Copyright 1991
  7.     John W. Small
  8.     All rights reserved
  9.  
  10.     Licensed users of FlexList are free to use and
  11.     modify this tool for use in their programs.
  12.  
  13.     PSW / Power SoftWare
  14.     P.O. Box 10072
  15.     McLean, VA 22102 8072 USA
  16.  
  17.     Voice: (703) 759-3838
  18.     CIS: 73757,2233
  19.  
  20. */
  21.  
  22. #ifndef PICKLIST_HPP
  23. #define PICKLIST_HPP
  24.  
  25. #include <string.h>
  26. #include <conio.h>
  27.  
  28. #ifndef FLEXLIST_CPP
  29. #include <flexlist.hpp>
  30. #endif
  31.  
  32. #ifndef PCWIN_HPP
  33. #include <pcwin.hpp>
  34. #endif
  35.  
  36.  
  37. #define MAX_PL_PREFIX  21
  38.  
  39.  
  40. class PickList : public FlexList {
  41.     int status;
  42. protected:
  43.     PalettE P;
  44.     char prefix[MAX_PL_PREFIX];
  45.     virtual int idle(int c) { return 0; }
  46.     virtual void displayStatus(void * D, int lineLen)
  47.         { cprintf("%-*.*s",lineLen,lineLen,
  48.             (char *)D); }
  49.     #pragma argsused
  50.     virtual void displayLine(void * D, int lineLen,
  51.             int cursor = 0)
  52.         { cprintf("%-*.*s",lineLen,lineLen,
  53.             (char *)D); }
  54.     #pragma argsused
  55.     virtual int xcursor(void * D, const char * prefix,
  56.         int pfLen) { return (pfLen+1); }
  57.     virtual int  match(char *pf, void * D)
  58.         { return !strncmpi(pf,(char *)D,strlen(pf)); }
  59. public:
  60.     static  Palette defaultP;
  61.     enum PL_PALETTE { COLOR, NORMAL, SELECT,
  62.         STATUS, AUX };
  63.     void setPalette(PalettE P = PalettE0)
  64.         { this->P = (P? P : defaultP); }
  65.     PickList(int status = 1,
  66.         PalettE P = PalettE0,
  67.         unsigned sizeofEntry = FLstrings,
  68.         unsigned maxEntries = 1024,
  69.         int (*comparE)(const void *, const void *)
  70.             = FLcomparE(strcmp))
  71.         : FlexList(sizeofEntry,maxEntries)
  72.     {
  73.         setPalette(P);
  74.         this->status = status;
  75.         setCompare(comparE);
  76.  
  77.     }
  78.     unsigned choose(unsigned curRow = 0);
  79.     void *  choice()  { return currentD(); }
  80.     #pragma argsused
  81.     virtual int doIt(void * D)  { return 0; }
  82.     virtual void * addD(void * D)  { return (Compare()?
  83.         insSortD(D) : insQD(D)); }
  84.     virtual int  subtractD(void * D);
  85. };
  86. typedef PickList * PickL;
  87. #define PickL0 ((PickL)0)
  88.  
  89.  
  90. class PickListWindow : public PickList, private TextWindow {
  91. protected:
  92.     void putTitle(const char *msg)
  93.         { TextWindow::putTitle(msg); }
  94.     void putFooter(const char *msg)
  95.         { TextWindow::putFooter(msg); }
  96.     virtual void dressWindow() { return; }
  97.     virtual unsigned paneWidth() { return 0; }
  98. public:
  99.     TextWindow::setPalette;
  100.     PickListWindow(int status = 1,
  101.         PalettE PLP = PalettE0,
  102.         PalettE TWP = PalettE0,
  103.         unsigned sizeofEntry = FLstrings,
  104.         unsigned maxEntries = 1024,
  105.         int (*comparE)(const void *, const void *)
  106.             = FLcomparE(strcmp))
  107.         : PickList(status,PLP,sizeofEntry,
  108.             maxEntries,comparE),
  109.         TextWindow(TWP) {}
  110.     unsigned choose(int left, int top, int right,
  111.         int bottom, unsigned curRow = 0);
  112.     unsigned choose(unsigned curRow = 0);
  113. };
  114. typedef PickListWindow *PickLW;
  115. #define PickLW0 ((PickLW)0)
  116.  
  117.  
  118. #endif
  119.